package net.codeyouth.myblog.user.bean;

import java.util.List;

/**
 * @author Frank create on 2016/1/31 16:59
 */
public class Page<T> {

  private int page;
  private int pageSize;
  private int totalPages;
  private int totalRecords;
  private int prevPage;
  private int nextPage;
  private List<T> data;

  public Page(int page, int pageSize, int totalRecords, List<T> data) {
    this.page = page;
    this.pageSize = pageSize;
    this.totalRecords = totalRecords;
    this.data = data;
    this.totalPages = totalRecords / pageSize + (totalRecords % pageSize == 0 ? 0 : 1);
  }

  public int getPage() {
    return page;
  }

  public void setPage(int page) {
    this.page = page;
  }

  public int getPageSize() {
    return pageSize;
  }

  public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
  }

  public int getTotalPages() {
    return totalPages;
  }

  public void setTotalPages(int totalPages) {
    this.totalPages = totalPages;
  }

  public int getTotalRecords() {
    return totalRecords;
  }

  public void setTotalRecords(int totalRecords) {
    this.totalRecords = totalRecords;
  }

  public int getPrevPage() {
    if (page - 1 <= 1) {
      return 1;
    }
    return page - 1;
  }

  public void setPrevPage(int prevPage) {
    this.prevPage = prevPage;
  }

  public int getNextPage() {
    if (page + 1 >= totalPages) {
      return totalPages;
    }
    return page + 1;
  }

  public void setNextPage(int nextPage) {
    this.nextPage = nextPage;
  }

  public List<T> getData() {
    return data;
  }

  public void setData(List<T> data) {
    this.data = data;
  }

}
